<template>
    <view class="bg-content">
        <scroll-view scroll-x="true">
            <div class="table table-bordered" style="background-color: white; text-align: center; width: 400px; overflow: auto;">
                <div class="tr">
                    <div class="td text-center bold">售后类型</div>
                    <div class="td text-center bold">有效天数</div>
                    <div class="td text-center bold">显示顺序</div>
                    <div class="td text-center bold">操作</div>
                </div>
                <div class="tr" v-for="(item, index) in tbGoodsAfterSaleList" :key="item.id">
                    <div class="td">{{item.typeText | toEmptyStr}}</div>
                    <div class="td">{{item.days | toEmptyStr}}</div>
                    <div class="td">{{item.displayOrder | toEmptyStr}}</div>
                    <div class="td">
                        <div style="margin-top: 5px; text-decoration: underline;"
                             @click="navigateTo('/pages/sub/sub2-store-platform/store-platform/store-platform-goods-manage/store-platform-goods/store-platform-goods-after-sale/store-platform-goods-after-sale-edit/index', null, item)">
                            编辑
                        </div>
                        <div style="margin-top: 10px; margin-bottom: 10px; text-decoration: underline;" @click="deleteItem(item, index)">
                            删除
                        </div>
                    </div>
                </div>
            </div>
        </scroll-view>

        <div style="padding-top: 50px;" v-if="!tbGoodsAfterSaleList.length">
            <u-empty text="数据为空" mode="data"></u-empty>
        </div>

        <div style="padding-bottom: 5px;"></div>

        <u-button
                @click="navigateTo(`/pages/sub/sub2-store-platform/store-platform/store-platform-goods-manage/store-platform-goods/store-platform-goods-after-sale/store-platform-goods-after-sale-add/index?goodsId=${goodsId}`, null, findTbGoodsAfterSaleList)">
            添加售后服务
        </u-button>
    </view>
</template>

<script>

    import {TbGoodsAfterSaleService} from "@/dev/services/tb-goods-after-sale.service";
    import {CommonUtil} from "@/dev/core/utils/common.util";

    export default {
        props: ["goodsId"],
        data() {
            return {
                tbGoodsAfterSaleList: []
            }
        },
        onReady() {
            const _self = this;
        },
        methods: {
            findTbGoodsAfterSaleList() {
                const _self = this;
                new TbGoodsAfterSaleService().findTbGoodsAfterSaleList({
                    goodsId: _self.goodsId
                }).then(result => {
                    _self.tbGoodsAfterSaleList = [];
                    _self.$nextTick(() => {
                        _self.tbGoodsAfterSaleList = result;
                    });
                });
            },
            /**
             * 删除
             */
            deleteItem(item, index) {
                const _self = this;
                CommonUtil.alert({
                    title: '提示！',
                    content: '确定删除吗？',
                    showCancel: true, // 是否显示取消按钮
                    success: function (res) {
                        if (res.cancel) { // 点击取消,默认隐藏弹框
                        } else { // 点击确定
                            new TbGoodsAfterSaleService().batchDeleteTbGoodsAfterSaleByIds(item.id).then(result => {
                                _self.tbGoodsAfterSaleList.splice(index, 1);
                                CommonUtil.toast('删除成功');
                            });
                        }
                    }
                });
            }
        }
    }
</script>

<style lang="scss" scoped>
</style>
